package com.leapp.sk.ui.activity.notify

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.example.mvp.view.imgselector.ImageSelector
import com.leapp.sk.R
import com.leapp.sk.binder.BaseBinder
import com.leapp.sk.inter.ImagePathInterface
import com.leapp.sk.ui.activity.classs.ChoseClassActivity
import com.example.util.finallist.CHOSE_CLASS_NAME
import com.example.util.finallist.CODE_205
import com.leapp.sk.util.getResultFile
import com.leapp.sk.viewdelegate.notify.SendNotifyDelegate

/**
 * 发送通知
 * @author  chaohaipeng  on 2018/8/10.
 */
class SendNotifyActivity :BaseActivityMVP<SendNotifyDelegate>(), ImagePathInterface {
    override fun getArrayImagePath(path: List<String>) {
        imageData.addAll(path)
        viewDelegate.notifyIvAdapter()
    }

    private val imageData= mutableListOf<String>()
    override fun initDate() {
        viewDelegate.initAdapter(this,imageData)
    }
    override fun bindEvenListener() {
        viewDelegate.setOnClickListener(View.OnClickListener {
            pickImage()
        }, R.id.iv_asn_chose_image)

        viewDelegate.setOnClickListener(View.OnClickListener {
           val intent=Intent(this,ChoseClassActivity::class.java)
            startActivityForResult(intent,CODE_205)

        }, R.id.rl_asn_chose_class)
        viewDelegate.setOnClickListener(View.OnClickListener {
           if (!TextUtils.isEmpty(viewDelegate.getTitle())&&!TextUtils.isEmpty(viewDelegate.getContent())){

           }
        }, R.id.tv_sna_send_notify)




    }
    /**
     * 照片选择
     */
    private fun pickImage() {
        ImageSelector.getInstance()
                .setSelectModel(ImageSelector.MULTI_MODE)
                .setMaxCount(9)
                .setGridColumns(3)
                .setShowCamera(true)
                .startSelect(this)
    }
    override fun getDelegateClass(): Class<SendNotifyDelegate> {
        return SendNotifyDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.string_notify_send_not))
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        getResultFile(requestCode, resultCode, data, this, this)

        when(requestCode){
            CODE_205->{
                if (resultCode==CODE_205){
                    val choseEntity: String?= data?.getStringExtra(CHOSE_CLASS_NAME)
                    viewDelegate.setClass(choseEntity)
                }
            }


        }

    }
}